<template>
  <div>
    <!-- <el-row>
      <el-col :span="24" class="addRole">

      </el-col>
    </el-row> -->
    <!-- 29所列表 -->
    <el-form v-model="codeObj" @submit.native.prevent>
      <el-form-item>
        <el-input type="text" ref="coderInput" v-model="codeObj.serchCode" @keyup.enter.native="submitCoder"  auto-complete="off" style="width:600px;height:28px; float:left;margin-right:10px;" placeholder="图纸条码" >
          <template slot="prepend">图纸条码</template>
        </el-input>
        <!-- <el-button type="primary" @click="showDialogForCheck">报检单</el-button> -->
      </el-form-item>
    </el-form>
        <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="searchTop">
              <el-form-item label="编码" >
                  <el-input v-model="searchTop.code29" clearable></el-input>
              </el-form-item>            
              <el-button type="primary" @click="searchTopBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>
  <el-tabs type="border-card" v-model="activeName" @tab-click="handleClick">
    <el-tab-pane label="待处理" name="1">
      <el-table :data="tableList" stripe border class="user-table"    style="width: 100%;">
<el-table-column fixed  prop="reproduce" label="类型" min-width="80" align="center">
                    <template slot-scope="scope">
                        <span v-html="scope.row.reproduce ===1?'<span style=\'color:red;font-weight:bolder;padding:5px;background:yellow\'>返工</span>':'正常'" ></span>
                    </template>
          </el-table-column>
          <el-table-column prop="taskSerialNo" label="任务流水号" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawName" label="图纸名称" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawCode" label="图纸编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code29" label="29所编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code" label="编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="wbPlanFinsihDate" label="外包完成日期" sortable min-width="100"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="showDialog(scope.row)">签收</el-button>
              <el-button type="text" @click="showDialogForQsAndKg(scope.row)">签收并开工</el-button>
              <el-button type="text" @click="showDialogForKg(scope.row)">开工</el-button>
            </template>
          </el-table-column>
        </el-table>
        
        <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    


    </el-tab-pane>
    <el-tab-pane label="处理中" name="2">
      <el-table :data="tableList" stripe border class="user-table"    style="width: 100%;">
        <el-table-column fixed  prop="reproduce" label="类型" min-width="80" align="center">
                    <template slot-scope="scope">
                        <span v-html="scope.row.reproduce ===1?'<span style=\'color:red;font-weight:bolder;padding:5px;background:yellow\'>返工</span>':'正常'" ></span>
                    </template>
          </el-table-column>
          <el-table-column prop="taskSerialNo" label="任务流水号" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawName" label="图纸名称" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawCode" label="图纸编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code29" label="29所编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code" label="编码" sortable min-width="100"></el-table-column>
           <el-table-column prop="processDetail.startTime" label="开工时间" sortable min-width="100"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="showDialog(scope.row)">送检</el-button>
              <el-button type="text" @click="showDialogForCheck(scope.row)">送检详情</el-button>
              <!-- <el-button type="text" @click="showDialogForZj(scope.row)">装夹详情</el-button> -->
              <el-button type="text" @click="showDialogForWg(scope.row)">完工</el-button>
            </template>
          </el-table-column>
      </el-table>  
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </el-tab-pane>
    <el-tab-pane label="已完工" name="3">
      <el-table :data="tableList" stripe border class="user-table"    style="width: 100%;">
        <el-table-column fixed  prop="reproduce" label="类型" min-width="80" align="center">
                    <template slot-scope="scope">
                        <span v-html="scope.row.reproduce ===1?'<span style=\'color:red;font-weight:bolder;padding:5px;background:yellow\'>返工</span>':'正常'" ></span>
                    </template>
          </el-table-column>
          <el-table-column prop="taskSerialNo" label="任务流水号" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawName" label="图纸名称" sortable min-width="100"></el-table-column>
          <el-table-column prop="drawCode" label="图纸编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code29" label="29所编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="code" label="编码" sortable min-width="100"></el-table-column>
          <el-table-column prop="processDetail.endTime" label="完工时间" sortable min-width="100"></el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button type="text" @click="showDialog(scope.row)">送检</el-button>
              <el-button type="text" @click="showDialogForCheck(scope.row)">送检详情</el-button>
              <el-button type="text" @click="alert('详情')">详情</el-button>
              <!-- <el-button type="text" @click="showDialogForZj(scope.row)">装夹详情</el-button> -->
            </template>
          </el-table-column>
      </el-table>  
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="total"></el-pagination>
    </el-tab-pane>
  </el-tabs>
    <el-dialog  :title="dialog.title" :visible.sync="dialog.isShow"  v-dialogDrag width="700px">
          <el-form :inline="true" :model="checkObj">
              <el-form-item label="设备" >
                <el-select v-model="checkObj.mac" filterable clearable placeholder="请选择" >
                  <el-option
                    v-for="item in machineList"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
                  </el-option>
                </el-select>
                  <!-- <el-input v-model="checkObj.mac"></el-input> -->
              </el-form-item>
              <el-form-item label="检验" >
                <el-select v-model="checkObj.checkType" filterable clearable placeholder="请选择" >
                  <el-option value="1" label="首检"></el-option>
                  <el-option value="2" label="抽检"></el-option>
                  <el-option value="3" label="巡检"></el-option>
                  <el-option value="4" label="送检"></el-option>
                </el-select>
                  <!-- <el-input v-model="checkObj.checkType"></el-input> -->
              </el-form-item>
              <el-button type="primary" @click="insertCheck">确认</el-button>
          </el-form>        
    </el-dialog>
    <el-dialog  :title="dialogForCheck.title" :visible.sync="dialogForCheck.isShow"  v-dialogDrag width="1100px">
        <!-- 查询 -->
      <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="checkSearch.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="图纸" >
                  <el-input v-model="checkSearch.drawName"></el-input>
              </el-form-item>
              <el-form-item label="任务单号" >
                  <el-input v-model="checkSearch.taskNo"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="checkSearch.makeNo"></el-input>
              </el-form-item>
              <el-form-item label="任务流水号" >
                  <el-input v-model="checkSearch.taskSerialNo"></el-input>
              </el-form-item>
              <el-form-item label="29所编码" >
                  <el-input v-model="checkSearch.code29"></el-input>
              </el-form-item>
              <el-form-item label="自定义编码" >
                  <el-input v-model="checkSearch.code"></el-input>
              </el-form-item>
              <el-form-item label="状态" >
                <el-select v-model="checkSearch.state" filterable clearable placeholder="请选择" >
                  <el-option value="0" label="待办"></el-option>
                  <el-option value="1" label="已办"></el-option>
                </el-select>
              </el-form-item>   
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
      </el-popover>   
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="dialogForCheck.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="dialogForCheck.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="dialogForCheck.total"></el-pagination>
      <el-table :data="tableCheckList" stripe border class="user-table"    style="width: 100%;">
        <el-table-column prop="name" label="工序名称" sortable min-width="100"></el-table-column>
        <el-table-column prop="content" label="检验内容" sortable min-width="100"></el-table-column>
        <el-table-column prop="creatorName" label="送检人" sortable min-width="100"></el-table-column>
        <el-table-column prop="resultNums" label="合格数量" sortable min-width="100"></el-table-column>
        <el-table-column prop="macName" label="设备" sortable min-width="100"></el-table-column>
        <el-table-column prop="createTime" label="送检时间" sortable min-width="100">
          <template slot-scope="scope">
            {{timestampToTime(scope.row.createTime,'yyyy-mm-dd hh:mm:ss')}}
          </template>
        </el-table-column>
        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="showDialogForCheckDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </el-dialog>
    <el-dialog  :title="dialogForZj.title" :visible.sync="dialogForZj.isShow"  v-dialogDrag width="1100px">
        <!-- 查询 -->
        <!-- <el-popover placement="bottom-start" width="1000" style="margin-right:10px;" trigger="click">
          <el-form :inline="true" :model="search">
              <el-form-item label="图纸编号" >
                  <el-input v-model="checkSearch.drawCode"></el-input>
              </el-form-item>
              <el-form-item label="图纸" >
                  <el-input v-model="checkSearch.drawName"></el-input>
              </el-form-item>
              <el-form-item label="任务单号" >
                  <el-input v-model="checkSearch.taskNo"></el-input>
              </el-form-item>
              <el-form-item label="生产令号" >
                  <el-input v-model="checkSearch.makeNo"></el-input>
              </el-form-item>
              <el-form-item label="任务流水号" >
                  <el-input v-model="checkSearch.taskSerialNo"></el-input>
              </el-form-item>
              <el-form-item label="29所编码" >
                  <el-input v-model="checkSearch.code29"></el-input>
              </el-form-item>
              <el-form-item label="自定义编码" >
                  <el-input v-model="checkSearch.code"></el-input>
              </el-form-item>
              <el-form-item label="状态" >
                <el-select v-model="checkSearch.state" filterable clearable placeholder="请选择" >
                  <el-option value="0" label="待办"></el-option>
                  <el-option value="1" label="已办"></el-option>
                </el-select>
              </el-form-item>   
              <el-button type="primary" @click="searchBtn">确认</el-button>
          </el-form>
          <el-button slot="reference" type="primary" icon="el-icon-search">查询</el-button>
        </el-popover>    -->
      <el-pagination  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="dialogForZj.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="dialogForZj.pagesize" layout="total, sizes, prev, pager, next, jumper" :total="dialogForZj.total"></el-pagination>
      <el-table :data="tableZjList" stripe border class="user-table"    style="width: 100%;">
        <el-table-column prop="creatorName" label="装夹人" sortable min-width="100"></el-table-column>
        <el-table-column prop="startTime" label="开始时间" sortable min-width="100">
          <template slot-scope="scope" v-if="scope.row.startTime != null && scope.row.startTime != undefined">
            {{timestampToTime(scope.row.startTime,'yyyy-mm-dd hh:mm:ss')}}
          </template>
        </el-table-column>
        <el-table-column prop="endTime" label="结束时间" sortable min-width="100">
          <template slot-scope="scope" v-if="scope.row.endTime != null && scope.row.endTime != undefined">
            {{timestampToTime(scope.row.endTime,'yyyy-mm-dd hh:mm:ss')}}
          </template>
        </el-table-column>
        <el-table-column prop="haoshi" label="耗时(分)" sortable min-width="100">
          <template slot-scope="scope" v-if="scope.row.endTime != null && scope.row.endTime != undefined">
            {{onlyone((scope.row.endTime - scope.row.startTime) / 60000 )}}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="haoshi" label="耗时(分)" sortable min-width="100"></el-table-column> -->
        <!-- <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button type="text" @click="showDialogForCheckDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column> -->
      </el-table>
    </el-dialog>
  </div>
</template>
<script>
import planApi from 'plugins/axios/planApi.js';
import baseApi from 'plugins/axios/baseApi.js';


export default {
  components: {

  },
  data(){
    return {
      codeObj:{
        serchCode:'',
      },
      searchTop:{
        code29:'',
      },
      search:{},
      checkObj:{
        mac:'',
        checkType:'', 
      },
      checkSearch:{

      },
      machineList:[],
      tableList:[],
      tableCheckList:[],
      tableZjList:[],
      currentPage: 1,
      pagesize: 10,
      total:0,
      type:1,
      code29:'',
      isSxpc:sessionStorage.getItem('ROLE_sxpc'),//当前用户是否拥有数铣排程权限
      isPtxf:sessionStorage.getItem('ROLE_ptxf'),//当前用户是否拥有任务下发权限
      dialog:{
        isShow:false,
        title:'',
        currentRow:'',
      },
      dialogForCheck:{
        isShow:false,
        title:'',
        currentRow:'',
        currentPage: 1,
        pagesize: 10,
        total:0,
      },
      dialogForZj:{
        isShow:false,
        title:'',
        currentRow:'',
        currentPage: 1,
        pagesize: 10,
        total:0,
      },
      dialogForCheckDetail:{
        isShow:false,
        title:'',
        currentRow:'',
        currentPage: 1,
        pagesize: 10,
        total:0,
      },
      activeName:'1',
    }
  },
  mounted(){
    this.status = this.$route.query.status;
    this.nameType= this.$route.query.name
    this.getTablList();
    
  },
  created(){
    this.$nextTick(()=>{
          this.$refs["coderInput"].focus();
          this.queryTableList();
          this.queryMachineList();
    });
  },
  watch: {
  },
  methods:{
    searchTopBtn(){
      let self = this;
      self.queryTableList();
    },
    handleClick() {
      let self = this;
      if(this.activeName === '1'){
        self.type=1;
        self.queryTableList();
      }else if(this.activeName === '2'){
        self.type=2;
        self.queryTableList();
      }else if(this.activeName === '3'){
        self.type=3;
        self.queryTableList();
      }
    },
    searchBtn(){
      let self = this;
      self.queryTableCheckList();
    },
    //查询机器列表    
    queryMachineList(){
      let self = this;
      planApi.queryMachineList().then(res=>{
        self.machineList = res.content;
      });
    },
    showDialogForCheckDetail(row){
      let self = this;
      self.dialogForCheckDetail.isShow = true;
      self.dialogForCheckDetail.currentRow = row;
    },
    showDialogForZj(row){
      let self = this;
      self.dialogForZj.isShow = true;
      self.dialogForZj.currentRow = row;
      self.queryTableZjList();
    },
    showDialogForWg(row){
      let self = this;
          planApi.updateRwwg(row.processDetailId).then(res=>{
            self.$message.success("完工成功");
            self.queryTableList();
          });
    },
    showDialogForQsAndKg(row){//签收并开工
      let self = this;
          planApi.rwqsAndKg(row.processDetailId).then(res=>{
            self.$message.success("签收并开工成功");
            self.queryTableList();
          });
    },
    showDialogForKg(row){//开工
      //开工
      let self = this;
          planApi.updateRwkg(row.processDetailId).then(res=>{
            self.$message.success("开工成功");
            this.queryTableList();
          });
    },
    showDialogForCheck(row){
      let self = this;
      self.dialogForCheck.isShow = true;
      self.dialogForCheck.currentRow = row;
      self.queryTableCheckList();
    },
    showDialog(row){
      let self = this;
      self.dialog.currentRow =  row;
      self.dialog.isShow = true;
    },
    //报检
    insertCheck(){
      let self = this;
      let param = {
        mac:self.checkObj.mac,
        checkType:self.checkObj.checkType,
        processDetailId:self.dialog.currentRow.processDetailId,
      };
      planApi.insertCheck(param).then(res=>{
        self.$message({message:'操作成功',type:'success'});
        self.dialog.isShow = false;
      });
    },
    queryTableList(){
      let self = this;
      let param = {
        currentPage:self.currentPage,
        pageSize:self.pagesize,
        code29:self.searchTop.code29,
        type:self.type,
      }  
      // planApi.selectCurrentUserPdMsg(self.currentPage,self.pagesize).then(res=>{
      planApi.selectCurrentUserPxMsg(param).then(res=>{
          self.tableList = res.content.records;
          self.total = res.content.total;
      });
    },
    queryTableCheckList(){
      let self = this; 
      let param = {
        currentPage:self.dialogForCheck.currentPage,
        pageSize:self.dialogForCheck.pagesize,
        taskNo:self.checkSearch.taskNo,
        taskSerialNo:self.checkSearch.taskSerialNo,
        makeNo:self.checkSearch.makeNo,
        drawCode:self.checkSearch.drawCode,
        drawName:self.checkSearch.drawName,
        code29:self.checkSearch.code29,
        code:self.checkSearch.code,
        state:self.checkSearch.state,
        processDetailId:self.dialogForCheck.currentRow.processDetailId
      }
      planApi.selectCheck(param).then(res=>{
          self.tableCheckList = res.content.records;
          self.dialogForCheck.total = res.content.total;
      });
    },
    queryTableZjList(){
      let self = this; 
      planApi.selectSxzjList(self.dialogForZj.currentRow.processDetailId).then(res=>{
          self.tableZjList = res.content;
          self.dialogForZj.total = res.content.length;
      });
    },
    submitCoder(){
      let self = this;
      // alert(self.codeObj.serchCode);
      planApi.pxGzgc(self.codeObj.serchCode).then(res=>{
          // self.tableList = res.content;
          self.codeObj.serchCode='';
          self.$refs["coderInput"].focus(); 
      });
    },
    /* 只保留一位小数 */
    onlyone(val) {
      val = Math.round(val * 10) / 10;
      let xsd = val.toString().split(".");
      if (xsd.length === 1) {
        val = val.toString() + ".0";
        return val;
      }
      return val;
    },
    /**时间格式化 */
    timeFormatter(row, column, cellValue, index){
      return cellValue?this.timestampToTime(cellValue,'yyyy-mm-dd'):'';
    },
    handleSizeChange(size) {
      this.pagesize = size;
      this.queryTableList();
    },
    handleCurrentChange(currentPage) {
      this.currentPage = currentPage;
      this.queryTableList();
    },
    getTablList(){/**计划列表 */

    },
  }
}
</script>
<style lang="stylus" scoped>
  .addRole
    padding-bottom 10px
  .content-rowspan div
    padding-left: 13px;
    line-height: 46px;
    border-bottom: 1px solid #ECEDEE;
    &:last-child
      border-bottom:none
</style>